package com.inxedu.os.edu.controller.course;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.inxedu.os.edu.pojo.EduWebsiteCourse;
import com.inxedu.os.edu.service.course.AdminWebSiteCourse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("admin")
@Api(value = "推荐课程分类接口", tags = "推荐课程分类Controller")
public class AdminWebsiteCourseController {
//    @InitBinder("websiteCourse")
//    public void initBinderWebsiteCourse(WebDataBinder binder) {
//        binder.setFieldDefaultPrefix("websiteCourse.");
//    }
    @Autowired
    private AdminWebSiteCourse webSiteCourse;
    //查询推荐课程分类
    @RequestMapping(value = "/website/websiteCoursePage",method = RequestMethod.GET)
    @ApiImplicitParam(name = "websiteCourse",value = "课程对象",dataType = "websiteCourse")
    @ApiOperation(value = "查询推荐课程分类",notes = "查询推荐课程分类")
    public String toWebsiteCourse(Model model,EduWebsiteCourse websiteCourse){
        List<EduWebsiteCourse> select =webSiteCourse.select(websiteCourse);
        model.addAttribute("websiteCourseList",select);
        return "view/inxedu/admin/website/course/websiteCourse_list";
    }

    //添加

    @RequestMapping(value = "/website/doAddWebsiteCourse",method = RequestMethod.GET)
    @ApiImplicitParam(name = "eduWebsiteCourse",value = "课程对象",dataType = "eduWebsiteCourse")
    @ApiOperation(value = "添加课程分类跳转页面",notes = "添加课程分类页面")
    public String toAddWebsiteCourse(Model model,@ModelAttribute("eduWebsiteCourse") EduWebsiteCourse eduWebsiteCourse){


        return "view/inxedu/admin/website/course/websiteCourse_add";
    }
    @RequestMapping(value = "/website/addCourse",method = RequestMethod.POST)
    @ApiImplicitParam(name = "eduWebsiteCourse",value = "课程对象",required = true,dataType = "eduWebsiteCourse")
    @ApiOperation(value = "添加课程分类",notes = "添加课程分类")
    public String AddWebsiteCourse(Model model,EduWebsiteCourse eduWebsiteCourse){
        int i = webSiteCourse.insetEduWebsiteCourse(eduWebsiteCourse);
        model.addAttribute("websiteCourse",i);
        return "redirect:/admin/website/websiteCoursePage";
    }

    //初始化修改页面
    @RequestMapping(value = "/website/doUpdateWebsiteCourse/{id}",method = RequestMethod.GET)
    @ApiImplicitParam(name = "id",value = "课程id",required = true,dataType = "id")
    @ApiOperation(value = "修改跳转页面",notes = "修改时跳转的页面,根据Id获取要修改的东西")
        public String updateWebsiteCourse(Model model,@PathVariable("id")int id){
            EduWebsiteCourse eduWebsiteCourse = webSiteCourse.selectAll(id);
            System.out.println(eduWebsiteCourse);
            model.addAttribute("websiteCourse",eduWebsiteCourse);
            return "view/inxedu/admin/website/course/websiteCourse_update";
    }
    //修改
    @RequestMapping(value = "/website/updateWebsiteCourse",method = RequestMethod.POST)
    @ApiImplicitParam(name = "course",value = "修改对象",required = true,dataType = "course")
    @ApiOperation(value = "修改方法",notes = "修改执行方法")
    public String update(EduWebsiteCourse course){
        webSiteCourse.update(course);
        return "redirect:/admin/website/websiteCoursePage";
    }
    //删除
    @RequestMapping(value = "/website/delWebsiteCourseById/{id}",method = RequestMethod.GET)
    @ApiImplicitParam(name = "id",value = "课程id",required = true,dataType = "id")
    @ApiOperation(value = "删除推荐分类",notes = "删除推荐分类")
    public String delete(@PathVariable("id")Integer id){
        int delete = webSiteCourse.delete(id);
        return "redirect:/admin/website/websiteCoursePage";
    }
}
